/*
 * Feb/13/2013
 * 
 * Group 2
 * ITCS 3146
 * 
 * Group Project
 * MULTICS Paging Algorithm
 * 
 */


package MULTICS;

import java.util.*;

public class PageDescriptor 
{
	// Dirty Bit
	private boolean referenced;

	private  int pageNumb;
	
	private boolean presAbs;
	
	// X00 Read Bit , 0X0 Write Bit, 00X Execute Bit
	private String protection;

	// Page frame number assigned to page
	private int pageFrameNumber;

	
	// Sets up protection, sets page number, set Pres/Abs bit, set reference bit
	PageDescriptor(int pageNumb, String protection1) 
	{
		Random generator = new Random();


	    // Same protection as parent segment
		this.protection = protection1;
		
		// Set page number
		this.pageNumb = pageNumb;
		
		
		// Pages not initially in memory
		presAbs = false;
		
		// Randomly select reference bit( RBIT in Page)
		int randNumb = generator.nextInt(2);
		
		if(randNumb == 1)
			referenced = true;
		else
			referenced = false;

	}
	
	
	// Used in PageFaultHandler
	// Returns page number
	public int returnPageNumb()
	{
		return pageNumb;
	}

	// Returns the page's assigned frame number 
	public int returnFrameNumber() 
	{
		return pageFrameNumber;
	}

	// Sets the page's frame number
	public void setFrameNumber(int frameNum) 
	{
		pageFrameNumber = frameNum;
	}

	// Returns (pred/abs bit) true if page is in RAM
	public boolean pageStatus()
	{
		return presAbs;
	}

	// Modifies pres/abs bit
	public void setPresAbs(boolean status) 
	{
		presAbs = status;
	}

	// Updates rbit
	public void updateReferenced(boolean status) 
	{
		referenced = status;

	}
	
	// Returns rbit
	public boolean returnReferenced()
	{
		return referenced;
	}

	// Return's pages protection
	public String returnProtection() 
	{
		return protection;
	}

}
